package org.hl7.fhir.r5.test.profiles.codegen;

import java.util.List;
import java.util.ArrayList;
import javax.annotation.Nullable;
import java.util.Date;


import org.hl7.fhir.r5.context.IWorkerContext;
import org.hl7.fhir.r5.model.*;
import org.hl7.fhir.r5.profilemodel.PEBuilder;
import org.hl7.fhir.r5.profilemodel.PEInstance;
import org.hl7.fhir.r5.profilemodel.PEBuilder.PEElementPropertiesPolicy;
import org.hl7.fhir.r5.profilemodel.gen.PEGeneratedBase;
import org.hl7.fhir.r5.profilemodel.gen.Min;
import org.hl7.fhir.r5.profilemodel.gen.Max;
import org.hl7.fhir.r5.profilemodel.gen.Label;
import org.hl7.fhir.r5.profilemodel.gen.Doco;
import org.hl7.fhir.r5.profilemodel.gen.BindingStrength;
import org.hl7.fhir.r5.profilemodel.gen.ValueSet;
import org.hl7.fhir.r5.profilemodel.gen.MustSupport;
import org.hl7.fhir.r5.profilemodel.gen.Definition;


// Generated by the HAPI Java Profile Generator, 5/11/24, 6:00 pm

/**
 * A medically related item or items, in a container or package.
 *
 */
public class PackagedProductDefinitionUvEpi extends PEGeneratedBase {

  public static final String CANONICAL_URL = "http://hl7.org/fhir/uv/emedicinal-product-info/StructureDefinition/PackagedProductDefinition-uv-epi|1.0.0";

  @Min("0") @Max("1") @Doco("")
  private String id;  // 

  @Min("0") @Max("*") @Doco("Additional content defined by implementations")
  @Definition("May be used to represent additional information that is not part of the basic definition of the resource. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.")
  private List<Extension> extensions = new ArrayList<>();  // Additional content defined by implementations

  @Min("0") @Max("*") @Doco("Extensions that cannot be ignored")
  @Definition("May be used to represent additional information that is not part of the basic definition of the resource and that modifies the understanding of the element that contains it and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.\n\nModifier extensions SHALL NOT change the meaning of any elements on Resource or DomainResource (including cannot change the meaning of modifierExtension itself).")
  private List<Extension> modifierExtensions = new ArrayList<>();  // Extensions that cannot be ignored

  @Min("0") @Max("*") @Doco("A unique identifier for this package as whole - not for the content of the package")
  @Definition("A unique identifier for this package as whole - not the the content of the package. Unique instance identifiers assigned to a package by manufacturers, regulators, drug catalogue custodians or other organizations.")
  private List<Identifier> identifiers = new ArrayList<>();  // A unique identifier for this package as whole - not for the content of the package

  @Min("1") @Max("1") @Doco("A name for this package. Typically as listed in a drug formulary, catalogue, inventory etc")
  @Definition("A name for this package. Typically what it would be listed as in a drug formulary or catalogue, inventory etc.")
  private String name;// @NotNull  // A name for this package. Typically as listed in a drug formulary, catalogue, inventory etc

  @Min("0") @Max("*") @Doco("The product that this is a pack for")
  @Definition("The product this package model relates to, not the contents of the package (for which see package.containedItem).")
  private List<Reference> packageFors = new ArrayList<>();  // The product that this is a pack for

  @Min("0") @Max("*") @Doco("A total of the complete count of contained items of a particular type/form, independent of sub-packaging or organization. This can be considered as the pack size. See also packaging.containedItem.amount (especially the long definition)")
  @Definition("A total of the complete count of contained items of a particular type/form, independent of sub-packaging or organization. This can be considered as the pack size. This attribute differs from containedItem.amount in that it can give a single aggregated count of all tablet types in a pack, even when these are different manufactured items. For example a pill pack of 21 tablets plus 7 sugar tablets, can be denoted here as '28 tablets'. This attribute is repeatable so that the different item types in one pack type can be counted (e.g. a count of vials and count of syringes). Each repeat must have different units, so that it is clear what the different sets of counted items are, and it is not intended to allow different counts of similar items (e.g. not '2 tubes and 3 tubes'). Repeats are not to be used to represent different pack sizes (e.g. 20 pack vs. 50 pack) - which would be different instances of this resource.")
  private List<Quantity> containedItemQuantities = new ArrayList<>();  // A total of the complete count of contained items of a particular type/form, independent of sub-packaging or organization. This can be considered as the pack size. See also packaging.containedItem.amount (especially the long definition)

  @Min("0") @Max("*") @Doco("The legal status of supply of the packaged item as classified by the regulator.")
  @Definition("The legal status of supply of the packaged item as classified by the regulator.")
  private List<BackboneElement> legalStatusOfSupplies = new ArrayList<>();  // The legal status of supply of the packaged item as classified by the regulator.

  @Min("0") @Max("*") @Doco("Allows specifying that an item is on the market for sale, or that it is not available, and the dates and locations associated.")
  @Definition("Allows specifying that an item is on the market for sale, or that it is not available, and the dates and locations associated.")
  private List<MarketingStatus> marketingStatuses = new ArrayList<>();  // Allows specifying that an item is on the market for sale, or that it is not available, and the dates and locations associated.

  @Min("0") @Max("*") @Doco("Manufacturer of this package type (multiple means these are all possible manufacturers)")
  @Definition("Manufacturer of this package type. When there are multiple it means these are all possible manufacturers.")
  private List<Reference> manufacturers = new ArrayList<>();  // Manufacturer of this package type (multiple means these are all possible manufacturers)

  @Min("0") @Max("*") @Doco("Additional information or supporting documentation about the packaged product")
  @Definition("Additional information or supporting documentation about the packaged product.")
  private List<Reference> attachedDocuments = new ArrayList<>();  // Additional information or supporting documentation about the packaged product

  @Min("0") @Max("1") @Doco("A packaging item, as a container for medically related items, possibly with other packaging items within, or a packaging component, such as bottle cap")
  @Definition("A packaging item, as a container for medically related items, possibly with other packaging items within, or a packaging component, such as bottle cap (which is not a device or a medication manufactured item).")
  private BackboneElement packaging;  // A packaging item, as a container for medically related items, possibly with other packaging items within, or a packaging component, such as bottle cap


  /**
   * Parameter-less constructor.
   *
   */
  public PackagedProductDefinitionUvEpi() {
  }

  /**
   * Construct an instance of the object, and fill out all the fixed values 
   *
   */
  public PackagedProductDefinitionUvEpi(IWorkerContext context) {
    workerContext = context;
    PEBuilder builder = new PEBuilder(context, PEElementPropertiesPolicy.EXTENSION, true);
    PEInstance src = builder.buildPEInstance(CANONICAL_URL, builder.createResource(CANONICAL_URL, false));
    load(src);
  }

  /**
   * Populate an instance of the object based on this source object 
   *
   */
  public static PackagedProductDefinitionUvEpi fromSource(IWorkerContext context, PackagedProductDefinition source) {
    PackagedProductDefinitionUvEpi theThing = new PackagedProductDefinitionUvEpi();
    theThing.workerContext = context;
    PEBuilder builder = new PEBuilder(context, PEElementPropertiesPolicy.EXTENSION, true);
    PEInstance src = builder.buildPEInstance(CANONICAL_URL, source);
    theThing.load(src);
    return theThing;
  }


  public void load(PEInstance src) {
    clear();
    if (src.hasChild("id")) {
      id = ((IdType) src.child("id").asDataType()).getValue();
    }
    for (PEInstance item : src.children("extension")) {
      extensions.add((Extension) item.asDataType());
    }
    for (PEInstance item : src.children("modifierExtension")) {
      modifierExtensions.add((Extension) item.asDataType());
    }
    for (PEInstance item : src.children("identifier")) {
      identifiers.add((Identifier) item.asDataType());
    }
    if (src.hasChild("name")) {
      name = ((StringType) src.child("name").asDataType()).getValue();
    }
    for (PEInstance item : src.children("packageFor")) {
      packageFors.add((Reference) item.asDataType());
    }
    for (PEInstance item : src.children("containedItemQuantity")) {
      containedItemQuantities.add((Quantity) item.asDataType());
    }
    for (PEInstance item : src.children("legalStatusOfSupply")) {
      legalStatusOfSupplies.add((BackboneElement) item.asElement());
    }
    for (PEInstance item : src.children("marketingStatus")) {
      marketingStatuses.add((MarketingStatus) item.asDataType());
    }
    for (PEInstance item : src.children("manufacturer")) {
      manufacturers.add((Reference) item.asDataType());
    }
    for (PEInstance item : src.children("attachedDocument")) {
      attachedDocuments.add((Reference) item.asDataType());
    }
    if (src.hasChild("packaging")) {
      packaging = (BackboneElement) src.child("packaging").asElement();
    }

  }

  /**
   * Build a instance of the underlying object based on this wrapping object 
   *
   */
  public PackagedProductDefinition build(IWorkerContext context) {
    workerContext = context;
    return build();
  }

  /**
   * Build a instance of the underlying object based on this wrapping object 
   *
   */
  public PackagedProductDefinition build() {
    PackagedProductDefinition theThing = new PackagedProductDefinition();
    PEBuilder builder = new PEBuilder(workerContext, PEElementPropertiesPolicy.EXTENSION, true);
    PEInstance tgt = builder.buildPEInstance(CANONICAL_URL, theThing);
    save(tgt, false);
    return theThing;
  }

  /**
   * Save this profile class into an existing resource (overwriting anything that 
   * exists in the profile) 
   *
   */
  public void save(IWorkerContext context, PackagedProductDefinition dest, boolean nulls) {
    workerContext = context;
    PEBuilder builder = new PEBuilder(context, PEElementPropertiesPolicy.EXTENSION, true);
    PEInstance tgt = builder.buildPEInstance(CANONICAL_URL, dest);
    save(tgt, nulls);
  }

  public void save(PEInstance tgt, boolean nulls) {
    tgt.clear("id");
    if (id != null) {
      tgt.makeChild("id").data().setProperty("value", new IdType(id));
    }
    tgt.clear("extension");
    for (Extension item : extensions) {
      tgt.addChild("extension", item);
    }
    tgt.clear("modifierExtension");
    for (Extension item : modifierExtensions) {
      tgt.addChild("modifierExtension", item);
    }
    tgt.clear("identifier");
    for (Identifier item : identifiers) {
      tgt.addChild("identifier", item);
    }
    tgt.clear("name");
    if (name != null) {
      tgt.makeChild("name").data().setProperty("value", new StringType(name));
    }
    tgt.clear("packageFor");
    for (Reference item : packageFors) {
      tgt.addChild("packageFor", item);
    }
    tgt.clear("containedItemQuantity");
    for (Quantity item : containedItemQuantities) {
      tgt.addChild("containedItemQuantity", item);
    }
    tgt.clear("legalStatusOfSupply");
    for (BackboneElement item : legalStatusOfSupplies) {
      tgt.addChild("legalStatusOfSupply", item);
    }
    tgt.clear("marketingStatus");
    for (MarketingStatus item : marketingStatuses) {
      tgt.addChild("marketingStatus", item);
    }
    tgt.clear("manufacturer");
    for (Reference item : manufacturers) {
      tgt.addChild("manufacturer", item);
    }
    tgt.clear("attachedDocument");
    for (Reference item : attachedDocuments) {
      tgt.addChild("attachedDocument", item);
    }
    tgt.clear("packaging");
    if (packaging != null) {
      tgt.addChild("packaging", packaging);
    }

  }

  public String getId() {
    return id;
  }

  public PackagedProductDefinitionUvEpi setId(String value) {
    this.id = value;
    return this;
  }

  public boolean hasId() {
    return id != null;
  }

  /**
   * May be used to represent additional information that is not part of the basic 
   * definition of the resource. To make the use of extensions safe and managable, 
   * there is a strict set of governance applied to the definition and use of 
   * extensions. Though any implementer can define an extension, there is a set of 
   * requirements that SHALL be met as part of the definition of the extension.
   *
   */
  public List<Extension> getExtensions() {
    if (extensions == null) { extensions = new ArrayList<>(); }
    return extensions;
  }

  public boolean hasExtensions() {
    return extensions != null && !extensions.isEmpty();
  }

  public Extension addExtension() {
    Extension theThing = new Extension();
    getExtensions().add(theThing);
    return theThing;
  }

  public boolean hasExtension(Extension item) {
    return hasExtensions() && extensions.contains(item);
  }

  public void removeExtension(Extension item) {
    if (hasExtension(item)) {
      extensions.remove(item);
    }
  }


  /**
   * May be used to represent additional information that is not part of the basic 
   * definition of the resource and that modifies the understanding of the element 
   * that contains it and/or the understanding of the containing element's 
   * descendants. Usually modifier elements provide negation or qualification. To 
   * make the use of extensions safe and managable, there is a strict set of 
   * governance applied to the definition and use of extensions. Though any 
   * implementer is allowed to define an extension, there is a set of requirements 
   * that SHALL be met as part of the definition of the extension. Applications 
   * processing a resource are required to check for modifier extensions.
   *
   * 
   *
   * Modifier extensions SHALL NOT change the meaning of any elements on Resource or 
   * DomainResource (including cannot change the meaning of modifierExtension 
   * itself).
   *
   */
  public List<Extension> getModifierExtensions() {
    if (modifierExtensions == null) { modifierExtensions = new ArrayList<>(); }
    return modifierExtensions;
  }

  public boolean hasModifierExtensions() {
    return modifierExtensions != null && !modifierExtensions.isEmpty();
  }

  public Extension addModifierExtension() {
    Extension theThing = new Extension();
    getModifierExtensions().add(theThing);
    return theThing;
  }

  public boolean hasModifierExtension(Extension item) {
    return hasModifierExtensions() && modifierExtensions.contains(item);
  }

  public void removeModifierExtension(Extension item) {
    if (hasModifierExtension(item)) {
      modifierExtensions.remove(item);
    }
  }


  /**
   * A unique identifier for this package as whole - not the the content of the 
   * package. Unique instance identifiers assigned to a package by manufacturers, 
   * regulators, drug catalogue custodians or other organizations.
   *
   */
  public List<Identifier> getIdentifiers() {
    if (identifiers == null) { identifiers = new ArrayList<>(); }
    return identifiers;
  }

  public boolean hasIdentifiers() {
    return identifiers != null && !identifiers.isEmpty();
  }

  public Identifier addIdentifier() {
    Identifier theThing = new Identifier();
    getIdentifiers().add(theThing);
    return theThing;
  }

  public boolean hasIdentifier(Identifier item) {
    return hasIdentifiers() && identifiers.contains(item);
  }

  public void removeIdentifier(Identifier item) {
    if (hasIdentifier(item)) {
      identifiers.remove(item);
    }
  }


  /**
   * A name for this package. Typically what it would be listed as in a drug 
   * formulary or catalogue, inventory etc.
   *
   */
  public String getName() {
    return name;
  }

  public PackagedProductDefinitionUvEpi setName(String value) {
    this.name = value;
    return this;
  }

  public boolean hasName() {
    return name != null;
  }

  /**
   * The product this package model relates to, not the contents of the package (for 
   * which see package.containedItem).
   *
   */
  public List<Reference> getPackageFors() {
    if (packageFors == null) { packageFors = new ArrayList<>(); }
    return packageFors;
  }

  public boolean hasPackageFors() {
    return packageFors != null && !packageFors.isEmpty();
  }

  public Reference addPackageFor() {
    Reference theThing = new Reference();
    getPackageFors().add(theThing);
    return theThing;
  }

  public boolean hasPackageFor(Reference item) {
    return hasPackageFors() && packageFors.contains(item);
  }

  public void removePackageFor(Reference item) {
    if (hasPackageFor(item)) {
      packageFors.remove(item);
    }
  }


  /**
   * A total of the complete count of contained items of a particular type/form, 
   * independent of sub-packaging or organization. This can be considered as the pack 
   * size. This attribute differs from containedItem.amount in that it can give a 
   * single aggregated count of all tablet types in a pack, even when these are 
   * different manufactured items. For example a pill pack of 21 tablets plus 7 sugar 
   * tablets, can be denoted here as '28 tablets'. This attribute is repeatable so 
   * that the different item types in one pack type can be counted (e.g. a count of 
   * vials and count of syringes). Each repeat must have different units, so that it 
   * is clear what the different sets of counted items are, and it is not intended to 
   * allow different counts of similar items (e.g. not '2 tubes and 3 tubes'). 
   * Repeats are not to be used to represent different pack sizes (e.g. 20 pack vs. 
   * 50 pack) - which would be different instances of this resource.
   *
   */
  public List<Quantity> getContainedItemQuantities() {
    if (containedItemQuantities == null) { containedItemQuantities = new ArrayList<>(); }
    return containedItemQuantities;
  }

  public boolean hasContainedItemQuantities() {
    return containedItemQuantities != null && !containedItemQuantities.isEmpty();
  }

  public Quantity addContainedItemQuantity() {
    Quantity theThing = new Quantity();
    getContainedItemQuantities().add(theThing);
    return theThing;
  }

  public boolean hasContainedItemQuantity(Quantity item) {
    return hasContainedItemQuantities() && containedItemQuantities.contains(item);
  }

  public void removeContainedItemQuantity(Quantity item) {
    if (hasContainedItemQuantity(item)) {
      containedItemQuantities.remove(item);
    }
  }


  /**
   * The legal status of supply of the packaged item as classified by the regulator.
   *
   */
  public List<BackboneElement> getLegalStatusOfSupplies() {
    if (legalStatusOfSupplies == null) { legalStatusOfSupplies = new ArrayList<>(); }
    return legalStatusOfSupplies;
  }

  public boolean hasLegalStatusOfSupplies() {
    return legalStatusOfSupplies != null && !legalStatusOfSupplies.isEmpty();
  }

  public boolean hasLegalStatusOfSupply(BackboneElement item) {
    return hasLegalStatusOfSupplies() && legalStatusOfSupplies.contains(item);
  }

  public void removeLegalStatusOfSupply(BackboneElement item) {
    if (hasLegalStatusOfSupply(item)) {
      legalStatusOfSupplies.remove(item);
    }
  }


  /**
   * Allows specifying that an item is on the market for sale, or that it is not 
   * available, and the dates and locations associated.
   *
   */
  public List<MarketingStatus> getMarketingStatuses() {
    if (marketingStatuses == null) { marketingStatuses = new ArrayList<>(); }
    return marketingStatuses;
  }

  public boolean hasMarketingStatuses() {
    return marketingStatuses != null && !marketingStatuses.isEmpty();
  }

  public MarketingStatus addMarketingStatus() {
    MarketingStatus theThing = new MarketingStatus();
    getMarketingStatuses().add(theThing);
    return theThing;
  }

  public boolean hasMarketingStatus(MarketingStatus item) {
    return hasMarketingStatuses() && marketingStatuses.contains(item);
  }

  public void removeMarketingStatus(MarketingStatus item) {
    if (hasMarketingStatus(item)) {
      marketingStatuses.remove(item);
    }
  }


  /**
   * Manufacturer of this package type. When there are multiple it means these are 
   * all possible manufacturers.
   *
   */
  public List<Reference> getManufacturers() {
    if (manufacturers == null) { manufacturers = new ArrayList<>(); }
    return manufacturers;
  }

  public boolean hasManufacturers() {
    return manufacturers != null && !manufacturers.isEmpty();
  }

  public Reference addManufacturer() {
    Reference theThing = new Reference();
    getManufacturers().add(theThing);
    return theThing;
  }

  public boolean hasManufacturer(Reference item) {
    return hasManufacturers() && manufacturers.contains(item);
  }

  public void removeManufacturer(Reference item) {
    if (hasManufacturer(item)) {
      manufacturers.remove(item);
    }
  }


  /**
   * Additional information or supporting documentation about the packaged product.
   *
   */
  public List<Reference> getAttachedDocuments() {
    if (attachedDocuments == null) { attachedDocuments = new ArrayList<>(); }
    return attachedDocuments;
  }

  public boolean hasAttachedDocuments() {
    return attachedDocuments != null && !attachedDocuments.isEmpty();
  }

  public Reference addAttachedDocument() {
    Reference theThing = new Reference();
    getAttachedDocuments().add(theThing);
    return theThing;
  }

  public boolean hasAttachedDocument(Reference item) {
    return hasAttachedDocuments() && attachedDocuments.contains(item);
  }

  public void removeAttachedDocument(Reference item) {
    if (hasAttachedDocument(item)) {
      attachedDocuments.remove(item);
    }
  }


  /**
   * A packaging item, as a container for medically related items, possibly with 
   * other packaging items within, or a packaging component, such as bottle cap 
   * (which is not a device or a medication manufactured item).
   *
   */
  public @Nullable BackboneElement getPackaging() { // BackboneElement is abstract 
    return packaging;
  }

  public PackagedProductDefinitionUvEpi setPackaging(BackboneElement value) {
    this.packaging = value;
    return this;
  }
  public boolean hasPackaging() {
    return packaging != null;
  }



  public void clear() {
    id = null;
    extensions.clear();
    modifierExtensions.clear();
    identifiers.clear();
    name = null;
    packageFors.clear();
    containedItemQuantities.clear();
    legalStatusOfSupplies.clear();
    marketingStatuses.clear();
    manufacturers.clear();
    attachedDocuments.clear();
    packaging = null;

  }

}
